import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';

import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(FixHistoryViewState state, Dispatch dispatch, ViewService viewService) {
  Widget _build(BuildContext context,int index) {
    FixListItemModel item = state.items[index];
    return Container(
      margin: EdgeInsets.only(left: 15, right: 15, top: 10),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(4)),
        color: Colors.white,
      ),
      padding: EdgeInsets.all(15),
      child: InkWell(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.only(bottom: 8),
              child: Text(
                item.titleStr,
                style: TextThemeConfig.Font15WithColor22,
              ),
            ),
            Padding(
              padding: EdgeInsets.only(bottom: 8),
              child: Row(
                children: [
                  Expanded(child: Text(
                    '类型：${item.itemTypeStr}',
                    style: TextThemeConfig.Font14WithColor22,
                  ),),
                  item.status != '5'
                      ? Container()
                      : Text(item.itemResult,style:item.result == '1' ? TextThemeConfig.Font14WithMainColor : TextThemeConfig.Font14WithColorRed,)
                ],
              ),
            ),
            Row(
              children: [
                Text(
                  item.itemType == '5'
                      ? '管点名：${item.userName}'
                      : '姓名：${item.userName}',
                  style: TextThemeConfig.Font14WithColor99,
                ),
                Padding(padding: EdgeInsets.only(left: 24)),
                item.phone.isEmpty
                    ? Container()
                    : Text(
                  '电话：${item.phone}',
                  style: TextThemeConfig.Font14WithColor99,
                ),
              ],
            ),
            Padding(
              padding: EdgeInsets.only(top: 8, bottom: 4),
              child: Text(
                '地址：${item.address}',
                style: TextThemeConfig.Font14WithColor99,
              ),
            ),
          ],
        ),
        onTap: () => CommonUtils.pushRoute(context, RoutePath.fixResultView,
            arguments: {
              'isDetail': true,
              'model': item,
            }),
      ),
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '维修记录'),
    body: state.items == null ? MyLoadingWidget() : ListView.builder(itemBuilder: _build,itemCount: state.items.length,),
  );
}
